package com.ygqh.baby.service.impl;

import com.wdt.api.WdtClient;
import com.wdt.api.constant.ApiPlatform;
import com.wdt.api.exception.WdtException;
import com.wdt.api.request.TradeQueryRequest;
import com.wdt.api.request.support.TradeQueryModel;
import com.wdt.api.response.TradeQueryResponse;
import com.ygqh.baby.service.WdtQybTradeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * 〈〉
 *
 * @author guohao
 * @date 2019/2/28 16:43
 * @since 1.0.0
 */
@Service
public class WdtQybTradeServiceImpl implements WdtQybTradeService {


    @Autowired
    private WdtClient wdtClient;

    @Override
    public TradeQueryResponse tradeQuery(TradeQueryRequest queryRequest) throws WdtException {

        return wdtClient.executeQuery(queryRequest);
    }

    @Override
    public TradeQueryResponse tradeQuery(Date startTime, Date endTime, String shopNo) throws WdtException {
        return tradeQuery(startTime, endTime, shopNo, null);
    }

    @Override
    public TradeQueryResponse tradeQuery(Date startTime, Date endTime, String shopNo, String warehouseNo) throws WdtException {

        return tradeQuery(startTime, endTime, shopNo, warehouseNo, false);
    }

    @Override
    public TradeQueryResponse tradeQuery(Date startTime, Date endTime, String shopNo, String warehouseNo, Boolean isTaoBao) throws WdtException {
        TradeQueryModel queryModel = new TradeQueryModel();
        queryModel.setStartTime(startTime);
        queryModel.setEndTime(endTime);
        queryModel.setShopNo(shopNo);
        queryModel.setWarehouseNo(warehouseNo);
        TradeQueryRequest queryRequest = new TradeQueryRequest();
        queryRequest.setBizModel(queryModel);
        if (isTaoBao) {
            queryRequest.setApiPlatform(ApiPlatform.QiMen);
        }
        return tradeQuery(queryRequest);
    }
}
